package com.antt.cn.test2.uis.activities;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;

import com.antt.cn.test2.R;
import com.antt.cn.test2.uis.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Ant on 2017/5/8  17:34
 * <p>
 * <p>
 *
 * @version 1.0.0
 * @auther Ant
 */

public class Test06 extends BaseActivity {

    private SharedPreferences app;

    @BindView(R.id.ac_test06_obt_obt01)
    Button obtSet;
    @BindView(R.id.ac_test06_obt_obt02)
    Button obtGet;


    @Override
    public int getLayoutId() {
        return R.layout.ac_test06_layout;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        app = getSharedPreferences("app", Context.MODE_PRIVATE);

    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {

    }

    @OnClick({R.id.ac_test06_obt_obt01, R.id.ac_test06_obt_obt02})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ac_test06_obt_obt01:
                set("ant", "app test sring from sb");

                break;
            case R.id.ac_test06_obt_obt02:
                String ss = (String) get("ant");
                obtGet.setText(ss == null ? "" : ss);
                break;
        }
    }


    public void set(String key, String value) {
        SharedPreferences.Editor edit = app.edit();
        edit.putString(key, value);
        edit.commit();
    }

    public Object get(String key) {
        String string = app.getString(key, null);
        return string;

    }
}
